home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Demos / Bowers Development / AppMaker 2.0b5 / Examples / ODF / Form / Sources / Frame.cpp < prev    next >
Encoding:
Text File  |  1996-06-03  |  10.4 KB  |  411 lines  |  [TEXT/CWIE]

  1. //========================================================================================
  2. //
  3. //    File:                Frame.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "Form.hpp"
  11.  
  12. #ifndef FRAME_H
  13. #include "Frame.h"
  14. #endif
  15.  
  16. #ifndef PART_H
  17. #include "Part.h"
  18. #endif
  19.  
  20. #ifndef COMMANDS_H
  21. #include "Commands.h"
  22. #endif
  23.  
  24. #ifndef CONTENT_H
  25. #include "Content.h"
  26. #endif
  27.  
  28. // ----- gadgets -----
  29.  
  30. #ifndef RECTVIEW_H
  31. #include "RectView.h"
  32. #endif
  33.  
  34. #ifndef PICTVIEW_H
  35. #include "PictView.h"
  36. #endif
  37.  
  38. #ifndef FWEDVIEW_H
  39. #include "FWEdView.h"
  40. #endif
  41.  
  42. #ifndef FWEDVIEW_H
  43. #include "FWEdView.h"
  44. #endif
  45.  
  46. #ifndef FWEDVIEW_H
  47. #include "FWEdView.h"
  48. #endif
  49.  
  50. #ifndef FWEDVIEW_H
  51. #include "FWEdView.h"
  52. #endif
  53.  
  54. #ifndef FWEDVIEW_H
  55. #include "FWEdView.h"
  56. #endif
  57.  
  58. #ifndef FWBUTTON_H
  59. #include "FWButton.h"
  60. #endif
  61.  
  62. #ifndef FWCLUSTR_H
  63. #include "FWClustr.h"
  64. #endif
  65.  
  66. #ifndef FWBUTTON_H
  67. #include "FWButton.h"
  68. #endif
  69.  
  70. #ifndef FWLISTBX_H
  71. #include "FWListBx.h"
  72. #endif
  73.  
  74. #ifndef FWBUTTON_H
  75. #include "FWButton.h"
  76. #endif
  77.  
  78. #ifndef FWBUTTON_H
  79. #include "FWButton.h"
  80. #endif
  81.  
  82. #ifndef FWPOPUP_H
  83. #include "FWPopup.h"
  84. #endif
  85.  
  86. #ifndef FWPOPUP_H
  87. #include "FWPopup.h"
  88. #endif
  89.  
  90. #ifndef FWCLUSTR_H
  91. #include "FWClustr.h"
  92. #endif
  93.  
  94. #ifndef FWBUTTON_H
  95. #include "FWButton.h"
  96. #endif
  97.  
  98. #ifndef FWCLUSTR_H
  99. #include "FWClustr.h"
  100. #endif
  101.  
  102. #ifndef FWBUTTON_H
  103. #include "FWButton.h"
  104. #endif
  105.  
  106. #ifndef FWBUTTON_H
  107. #include "FWButton.h"
  108. #endif
  109.  
  110. #ifndef FWBUTTON_H
  111. #include "FWSclBar.h"
  112. #endif
  113.  
  114. #ifndef FWBUTTON_H
  115. #include "FWSclBar.h"
  116. #endif
  117.  
  118. // ----- Framework Layer -----
  119.  
  120. #ifndef FWCONTXT_H
  121. #include "FWContxt.h"
  122. #endif
  123.  
  124. #ifndef FWUTIL_H
  125. #include "FWUtil.h"
  126. #endif
  127.  
  128. #ifndef FWPRESEN_H
  129. #include "FWPresen.h"
  130. #endif
  131.  
  132. #ifndef FWSELECT_H
  133. #include "FWSelect.h"
  134. #endif
  135.  
  136. #ifndef FWGROWBX_H
  137. #include "FWGrowBx.h"
  138. #endif
  139.  
  140. #ifndef FWSCLBAR_H
  141. #include "FWSclBar.h"
  142. #endif
  143.  
  144. // ----- OS Layer -----
  145.  
  146. #ifndef FWMENU_H
  147. #include "FWMenu.h"
  148. #endif
  149.  
  150. #ifndef FWEVENT_H
  151. #include "FWEvent.h"
  152. #endif
  153.  
  154. #ifndef FWALERT_H
  155. #include "FWAlert.h"
  156. #endif
  157.  
  158. // ----- Graphic Includes -----
  159.  
  160. #ifndef FWRECT_H
  161. #include "FWRect.h"
  162. #endif
  163.  
  164. #ifndef FWTXTBOX_H
  165. #include "FWTxtBox.h"
  166. #endif
  167.  
  168. #ifndef FWRECSHP_H
  169. #include "FWRecShp.h"
  170. #endif
  171.  
  172. // ----- OpenDoc Includes -----
  173.  
  174. #ifndef SOM_Module_OpenDoc_StdProps_defined
  175. #include <StdProps.xh>
  176. #endif
  177.  
  178. #ifndef SOM_ODDragItemIterator_xh
  179. #include <DgItmIt.xh>
  180. #endif
  181.  
  182. //========================================================================================
  183. // Runtime Information
  184. //========================================================================================
  185.  
  186. #ifdef FW_BUILD_MAC
  187. #pragma segment Form
  188. #endif
  189.  
  190. FW_DEFINE_AUTO(CFormFrame)
  191. FW_DEFINE_CLASS_M2(CFormFrame, FW_CFrame, FW_MReceiver)
  192.  
  193. //----------------------------------------------------------------------------------------
  194. // CFormFrame constructor
  195. //----------------------------------------------------------------------------------------
  196. CFormFrame::CFormFrame(Environment* ev, ODFrame* odFrame, FW_CPresentation* presentation, CFormContent* content)
  197.     : FW_CFrame(ev, odFrame, presentation, content->GetPart(ev)),
  198.     FW_MDraggableFrame(ev, this),
  199.     FW_MDroppableFrame(ev, this),    
  200.     fFormContent(content)
  201. {
  202. }
  203.  
  204. //----------------------------------------------------------------------------------------
  205. // CFormFrame destructor
  206. //----------------------------------------------------------------------------------------
  207.  
  208. CFormFrame::~CFormFrame()
  209. {
  210. }
  211.  
  212. //----------------------------------------------------------------------------------------
  213. //    CFormFrame::CanAcceptDrop
  214. //----------------------------------------------------------------------------------------
  215.  
  216. ODDragResult CFormFrame::CanAcceptDrop(Environment* ev, ODDragItemIterator* dragInfo)
  217. {
  218.     ODDragResult acceptDrop = FW_MDroppableFrame::CanAcceptDrop(ev, dragInfo);
  219.  
  220.     // ----- Test for 'TEXT' also -----
  221. #ifdef FW_BUILD_MAC
  222.     if (!acceptDrop)
  223.     {
  224.         for (ODStorageUnit* dragSU = dragInfo->First(ev); dragSU; dragSU = dragInfo->Next(ev))
  225.             if (dragSU->Exists(ev, kODPropContents, FW_CPart::gMacTEXTDataType, 0))    // 'TEXT' on Scrap
  226.                 return TRUE;
  227.     }
  228. #endif
  229.  
  230.     return acceptDrop;
  231. }
  232.  
  233. //----------------------------------------------------------------------------------------
  234. //    CFormFrame::DoMouseDown
  235. //----------------------------------------------------------------------------------------
  236.  
  237. FW_Boolean CFormFrame::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
  238. {
  239.     FW_Boolean result = FALSE;
  240.  
  241.     if (GetPresentation(ev)->GetSelection(ev)->IsMouseInDraggableItem(ev, this, theMouseEvent, FALSE))
  242.     {
  243.         result = this->Drag(ev, theMouseEvent);
  244.     }
  245.  
  246.     return result;
  247. }
  248.  
  249. //----------------------------------------------------------------------------------------
  250. // CFormFrame::DoMenu
  251. //----------------------------------------------------------------------------------------
  252.  
  253. FW_Boolean CFormFrame::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)
  254. {
  255.     FW_Boolean menuHandled = TRUE;
  256.     ODCommandID id = theMenuEvent.GetCommandID(ev);
  257.  
  258.     switch (id)
  259.     {
  260.         default:
  261.             menuHandled = FALSE;
  262.     }
  263.  
  264.     return menuHandled;
  265. }
  266.  
  267. //----------------------------------------------------------------------------------------
  268. // CFormFrame::DoAdjustMenus
  269. //----------------------------------------------------------------------------------------
  270.  
  271. FW_Boolean CFormFrame::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, 
  272.                                       FW_Boolean hasMenuFocus,
  273.                                       FW_Boolean isRoot)    // Override
  274. {
  275.     if (hasMenuFocus)
  276.     {
  277.         //---- Set up the Edit menu items ----
  278. #ifdef FW_BUILD_MAC
  279.         menuBar->EnableCommand(ev, kODCommandPaste, HasPropertyOnClipboard(ev, kODPropContents, FW_CPart::gMacTEXTDataType));
  280. #endif
  281.     }
  282.  
  283.     return FALSE;
  284. }
  285.  
  286. //----------------------------------------------------------------------------------------
  287. // CFormFrame::Draw
  288. //----------------------------------------------------------------------------------------
  289.  
  290. void CFormFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)    // Override
  291. {
  292.     FW_CViewContext        gc (ev, this, odFacet, invalidShape);
  293.  
  294.     // fill with background color
  295.     FW_CInk        fillInk (FW_CColor (221, 221, 221));    // LightGray
  296.     FW_CRect    bounds = this->GetBounds(ev);    
  297.     FW_CRectShape::RenderRect (gc, bounds, FW_kFill, fillInk);
  298. }
  299.  
  300. //----------------------------------------------------------------------------------------
  301. // CFormFrame::FrameShapeChanged
  302. //----------------------------------------------------------------------------------------
  303. // By default a FW_CFrame view is not refreshed entirely when resized.
  304. // You must decide if your content's appearance depends on the frame's size.
  305. // If it doesn't you don't need to override FrameShapeChanged().
  306. // Here we must redraw the whole frame everytime because the text is centered.
  307.  
  308. void CFormFrame::FrameShapeChanged(Environment* ev)
  309. {
  310.     FW_CFrame::FrameShapeChanged(ev);
  311.  
  312.     this->Invalidate(ev);
  313. }
  314.  
  315. //----------------------------------------------------------------------------------------
  316. //    CFormFrame::NewClipboardCommand
  317. //----------------------------------------------------------------------------------------
  318.  
  319. FW_CClipboardCommand* CFormFrame::NewClipboardCommand(Environment* ev, ODCommandID commandID)
  320. {
  321.     return FW_NEW(CFormEditCommand, (ev, commandID, fFormContent, this));
  322. }
  323.  
  324. //----------------------------------------------------------------------------------------
  325. //    CFormFrame::NewDragCommand
  326. //----------------------------------------------------------------------------------------
  327.  
  328. FW_CDragCommand* CFormFrame::NewDragCommand(Environment *ev, 
  329.                                             FW_CFrame* theFrame,
  330.                                             const FW_CMouseEvent& theMouseEvent)
  331. {
  332.     return FW_NEW(CFormDragCommand, (ev, fFormContent, theFrame));
  333. }
  334.  
  335. //----------------------------------------------------------------------------------------
  336. //    CFormFrame::NewDropCommand
  337. //----------------------------------------------------------------------------------------
  338.  
  339. FW_CDropCommand* CFormFrame::NewDropCommand(Environment* ev,
  340.                                              FW_CFrame* frame,
  341.                                              ODDragItemIterator* dropInfo, 
  342.                                              ODFacet* odFacet, 
  343.                                              const FW_CPoint& dropPoint)
  344. {
  345.     return FW_NEW(CFormDropCommand, (ev, fFormContent, this, dropInfo, odFacet, dropPoint));
  346. }
  347.  
  348. //----------------------------------------------------------------------------------------
  349. //    CFormFrame::CreateSubViews
  350. //----------------------------------------------------------------------------------------
  351.  
  352. void CFormFrame::CreateSubViews(Environment* ev)
  353. {
  354.     // WARNING: Make sure that classes created from resources won't be dead-stripped
  355.     //             Use the macro FW_DO_NOT_DEAD_STRIP for those classes which are not 
  356.     //             referenced anywhere else in your part's code.
  357.     FW_DO_NOT_DEAD_STRIP(FW_CGrowBox);
  358.     FW_DO_NOT_DEAD_STRIP(FW_CScrollBar);
  359.     FW_DO_NOT_DEAD_STRIP(FW_CScrollBarScroller);
  360.     FW_DO_NOT_DEAD_STRIP(CContentView);
  361.  
  362.     FW_DO_NOT_DEAD_STRIP(CPictView);
  363.     FW_DO_NOT_DEAD_STRIP(FW_CEditView);
  364.     FW_DO_NOT_DEAD_STRIP(FW_CEditView);
  365.     FW_DO_NOT_DEAD_STRIP(FW_CEditView);
  366.     FW_DO_NOT_DEAD_STRIP(FW_CEditView);
  367.     FW_DO_NOT_DEAD_STRIP(FW_CEditView);
  368.     FW_DO_NOT_DEAD_STRIP(FW_CButton);
  369.     FW_DO_NOT_DEAD_STRIP(CRadioGroup);
  370.     FW_DO_NOT_DEAD_STRIP(FW_CGroupBox);
  371.     FW_DO_NOT_DEAD_STRIP(FW_CButton);
  372.     FW_DO_NOT_DEAD_STRIP(FW_CRadioCluster);
  373.     FW_DO_NOT_DEAD_STRIP(FW_CListBox);
  374.     FW_DO_NOT_DEAD_STRIP(FW_CButton);
  375.     FW_DO_NOT_DEAD_STRIP(FW_CButton);
  376.     FW_DO_NOT_DEAD_STRIP(FW_CPopupMenu);
  377.     FW_DO_NOT_DEAD_STRIP(FW_CPopupMenu);
  378.     FW_DO_NOT_DEAD_STRIP(CRadioGroup);
  379.     FW_DO_NOT_DEAD_STRIP(FW_CGroupBox);
  380.     FW_DO_NOT_DEAD_STRIP(FW_CButton);
  381.     FW_DO_NOT_DEAD_STRIP(FW_CRadioCluster);
  382.     FW_DO_NOT_DEAD_STRIP(CRadioGroup);
  383.     FW_DO_NOT_DEAD_STRIP(FW_CGroupBox);
  384.     FW_DO_NOT_DEAD_STRIP(FW_CButton);
  385.     FW_DO_NOT_DEAD_STRIP(FW_CRadioCluster);
  386.     FW_DO_NOT_DEAD_STRIP(FW_CButton);
  387.     FW_DO_NOT_DEAD_STRIP(FW_CScrollBar);
  388.     FW_DO_NOT_DEAD_STRIP(FW_CScrollBar);
  389.  
  390.     CreateSubViewsFromResource(ev, kMainWindowResID);
  391. }
  392.  
  393. //----------------------------------------------------------------------------------------
  394. //    CFormFrame::HandleNotification
  395. //----------------------------------------------------------------------------------------
  396.  
  397. void CFormFrame::HandleNotification(Environment* ev, const FW_CNotification& notification)
  398. {
  399.     // Handle notification messages for the registered controls.
  400.     // GetMessage() allows to switch on the type of notification.  For each message
  401.     // we can down-cast "notification" directly to the right subclass, without
  402.     // having to use RTTI, because the message is unique to that type.
  403.  
  404.     switch (notification.GetMessage()) 
  405.     {
  406.         default:
  407.             FW_ASSERT("CFormFrame can't respond to this");
  408.             break;
  409.     }
  410. }
  411.